let
	gulp 	 = require('gulp'),
	cleanCss = require('gulp-clean-css'),
	uglify	 = require('gulp-uglify'),
	pump	 = require('pump'),
	sass	 = require('gulp-ruby-sass'),
	connect  = require('gulp-connect');

// 压缩CSS文件
gulp.task('minifyCss', function () {
	return gulp.src('./src/style/*.css').pipe(cleanCss()).pipe(gulp.dest('./dist/style/'));
});

// 压缩JS文件
gulp.task('minifyJS', function (cb) {
	/*pump([
        gulp.src('./src/js/*.js'),
        uglify(),
        gulp.dest('./dist/js/')
    ],
    cb
  );*/
  return gulp.src('./src/js/*.js').pipe(uglify()).pipe(gulp.dest('./dist/js/'));
});

// 编译Sass源代码
gulp.task('sass', function () {
	return sass('./src/sass/*.scss', {
		style: 'compressed'
	}).pipe(gulp.dest('./dist/sass/'));
});

// 刷新html
gulp.task('refresh', ['minifyJS', 'sass'], function () {
	return gulp.src('./index.html').pipe(connect.reload());
});

// 执行默认任务
gulp.task('default', ['refresh'], function () {
	// 开启一个服务器
	connect.server({
		livereload: true
	});
	// 监听CSS文件
	// gulp.watch('./src/style/*.css', ['minifyCss']);
	// 监听JS文件
	gulp.watch('./src/js/*.js', ['refresh']);
	// 监听Sass文件
	gulp.watch('./src/sass/*.scss', ['refresh']);
});